﻿<%@Import Namespace="System.IO"%>
<%@Import Namespace="System.Text"%>
<!--#include file="isLogin.aspx"-->
<script language="vbscript" runat="Server">
REM 23:06 2007-10-9
REM 客户端 服务器端信息沟通
Sub Main()
	Response.clear()
	dim act as String,data as String,tempStr as Object
	act=Request.Form("act")
	data=Request.Form("data")
	
	'response.write("act="&act)
	'response.write("data="&data)
	'response.end()
	if data<>"" then
		'data=System.Text.RegularExpressions.Regex.UnEscape(data)
	end if
	select case Lcase(act)
		case "fileexists":ServerReturn(ServerFileExists(data))
		case "filerename":
			tempStr=Split(data,"|")
			call ServerReturn(FileReName(tempStr(0),tempStr(1)))
		case "filedelete":
			ServerReturn(DeleteFile(data))
		case "createfolder":
			ServerReturn(createfolder(data))
		case "folderrename":
			tempStr=Split(data,"|")
			call ServerReturn(FolderReName(tempStr(0),tempStr(1)))
		case "folderdelete":
			ServerReturn(folderdelete(data))
		case "fileexists2":
			ServerReturn(FileExists(data))
	end select
End Sub

Sub ServerReturn(sreturnvalue as String)
	With Response
		.clear
		.ContentType = "text/xml; charset=utf-8"
		.Write("<?xml version='1.0' encoding='utf-8'?>")
		.Write("<root>")
		.Write("<returnvalue>" & Lcase(sreturnvalue) & "</returnvalue>")
		.Write("</root>")
		.End
	End With
End Sub

Function ServerFileExists(sFileName as String) as boolean
	dim mmArt as New WebNote.WebNote()
	ServerFileExists=FileExists(mmArt.DirectionPath & "/" & sFileName)
	mmArt=Nothing
End Function

Function FileExists(sFilePath) as boolean
	Dim FSO As System.IO.File
    FileExists=FSO.Exists(Server.Mappath(sFilePath))
    FSO = Nothing
End Function

Function FileReName(sFilePath,sReNameTo)
	'on error resume next
	dim FileBrowser_BasePath
	FileReName=False	
	dim mmArtRight As New WebNote.FileRight
	if Not mmArtRight.FileReName then
		Exit Function
	else
		FileBrowser_BasePath=mmArtRight.Path
	end if
	mmArtRight=Nothing
	
	if Left(Lcase(sFilePath),len(FileBrowser_BasePath))<>Lcase(FileBrowser_BasePath) or InStr(sFilePath,"../")>0 then
		Exit Function
	end if

	Dim mmFileInfo
	mmFileInfo =New FileInfo(Server.Mappath(sFilePath))
	
	'response.write(mmFileInfo.Directory.toString() & "\" & Replace(sReNameTo,mmFileInfo.Extension,"") & mmFileInfo.Extension)
	if mmFileInfo.Exists() then
		mmFileInfo.MoveTo(mmFileInfo.Directory.toString() & "\" & Replace(sReNameTo,mmFileInfo.Extension,"") & mmFileInfo.Extension)
		FileReName = True
	else
		FileReName = false
	end if
	if err.description<>"" then
		FileReName = false
	end if
End Function

Function DeleteFile(sFilePath)
	on error resume next
	dim FileBrowser_BasePath
	DeleteFile=False	
	dim mmArtRight As New WebNote.FileRight
	if Not mmArtRight.FileDelete then
		Exit Function
	else
		FileBrowser_BasePath=mmArtRight.Path
	end if
	mmArtRight=Nothing

	if Left(Lcase(sFilePath),len(FileBrowser_BasePath))<>Lcase(FileBrowser_BasePath) or InStr(sFilePath,"../")>0 then
		Exit Function
	end if
	'response.write(Server.Mappath(sFilePath))
	Dim mmFileInfo
	mmFileInfo =New FileInfo(Server.Mappath(sFilePath))
	if mmFileInfo.Exists() then
		mmFileInfo.Delete()
		DeleteFile = True
	else
		DeleteFile = false
	end if
	if err.description<>"" then
		DeleteFile = false
	end if
End Function

Function createFolder(sFolderPath)
	on error resume next
	
	dim FileBrowser_BasePath
	createFolder=False	
	dim mmArtRight As New WebNote.FileRight
	if Not mmArtRight.FolderCreate then
		Exit Function
	else
		FileBrowser_BasePath=mmArtRight.Path
	end if
	mmArtRight=Nothing
	
	sFolderPath=Replace(sFolderPath,".","")

	if Left(Lcase(sFolderPath),len(FileBrowser_BasePath))<>Lcase(FileBrowser_BasePath) or InStr(sFolderPath,"../")>0 then
		Exit Function
	end if

	'response.write(Server.Mappath(sFolderPath))

	if Not System.IO.Directory.Exists(Server.Mappath(sFolderPath)) then
		System.IO.Directory.CreateDirectory(Server.Mappath(sFolderPath))
		createFolder = true
	else
		createFolder= false
	end if
	
	if err.description<>"" then
		createFolder= false
	end if
	'mmDirectory = Nothing
End Function

Function FolderReName(sFolderPath,sReNameTo)
	'on error resume next
	dim FileBrowser_BasePath
	FolderReName=False	
	dim mmArtRight As New WebNote.FileRight
	if Not mmArtRight.FileReName then
		Exit Function
	else
		FileBrowser_BasePath=mmArtRight.Path
	end if
	mmArtRight=Nothing
	
	sReNameTo=Replace(sReNameTo,".","")
	
	if Left(Lcase(sFolderPath),len(FileBrowser_BasePath))<>Lcase(FileBrowser_BasePath) or InStr(sFolderPath,"../")>0 then
		Exit Function
	end if

	if System.IO.Directory.Exists(Server.Mappath(sFolderPath)) then
		System.IO.Directory.Move(Server.Mappath(sFolderPath),System.IO.Directory.GetParent(Server.Mappath(sFolderPath)).toString() & "\" & sReNameTo)
		FolderReName= True
	end if
	if err.description<>"" then
		FolderReName = false
	end if
End Function


Function folderdelete(sFolderPath)
	on error resume next
	dim FileBrowser_BasePath
	folderdelete=False	
	dim mmArtRight As New WebNote.FileRight
	if Not mmArtRight.FolderCreate then
		Exit Function
	else
		FileBrowser_BasePath=mmArtRight.Path
	end if
	mmArtRight=Nothing

	if Left(Lcase(sFolderPath),len(FileBrowser_BasePath))<>Lcase(FileBrowser_BasePath) or InStr(sFolderPath,"../")>0 then
		Exit Function
	end if
	'response.write(Server.Mappath(sFolderPath))
	if System.IO.Directory.Exists(Server.Mappath(sFolderPath)) then
		System.IO.Directory.Delete(Server.Mappath(sFolderPath),True)
		folderdelete = true
	end if
	
	if err.description<>"" then
		folderdelete = false
	end if
End Function
</script>

<%call Main()%>